import {
    getPayType,
    getProvince
} from "../../requestApi/options";

const dict = {
    state: {
        DICT: {
            // 支付类型 
            PAYTYPE: [],
            // 省市区 
            PROVINCE: null,
        }
    },

    mutations: {
        SET_PAYTYPE: (state, options) => {
            state.PAYTYPE = options;
        },
        SET_PROVINCE: (state, options) => {
            state.PROVINCE = options;
        }
    },

    actions: {
        GET_PAYTYPE({ commit }, data) {
            return new Promise((resolve, reject) => {
                getPayType({}).then(res => {
                    if (res.status === 200) {
                        let dataType = eval('(' + res.data + ')')
                        let array = [];
                        let dataObj = dataType.data
                        if (dataObj.constructor === Object) {
                            for (let key in dataObj) {
                                array.push({
                                    label: dataObj[key],
                                    value: key
                                });
                            }
                            commit("SET_PAYTYPE", array);
                            resolve()
                        } else {
                            reject('error')
                        }
                    } else {
                        reject('error')
                    }
                }).catch(error => {
                    reject(error)
                })
            })
        },
        GET_PROVINCE({ commit }, data) {
            // return new Promise((resolve, reject) => {
            //     getProvince({}).then(res => {
            //         if (res.status === 200) {
            //             commit("SET_PROVINCE", res.data);
            //             resolve()
            //         } else {
            //             reject('error')
            //         }
            //     }).catch(error => {
            //         reject(error)
            //     })
            // })
        }
    }
};

export default dict;